package com.google.code.UtopiaXml;

import java.util.LinkedHashSet;
import java.util.Set;

/**
 * Abstract base class for indicators with maxOccurs>1. It will generate a
 * separate class.
 *
 * @author Michael Simacek
 */
public abstract class MultiIndicator extends Indicator implements ClassTemplate {

    private Property prop;
    private String name;

    /**
     * Creates empty MultiIndicator
     *
     * @param name name which will be used for a class name.
     */
    public MultiIndicator(String name) {
        this.name = CodeBuilder.toUpperCamelCase(name);
        prop = new ListProperty(new ComplexTypeReference(name), name);
    }

    /**
     * Returns name of the generated class
     *
     * @return indicator name
     */
    public String getName() {
        return name;
    }

    @Override
    public ClassBuilder generateClass(String pkgName) {
        ClassBuilder clb = new ClassBuilder(getName(), pkgName);
        CodeBuilder cb = clb.getClassContentBuilder();

        for (IndicatorContent cont : getContent()) {
            clb.addProperties(cont.getProperties());
        }

        return clb;
    }

    @Override
    public Set<Property> getProperties() {
        Set<Property> props = new LinkedHashSet<>();
        props.add(prop);
        return props;
    }

    @Override
    public void generateParseMethod(CodeBuilder cb) {
    }
}
